package studentManagement;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/30 14:43
 */
public class Test {
    static Scanner inInt = new Scanner(System.in);
    static Scanner inString = new Scanner(System.in);
    static StudentDaoDB Sao = new StudentDaoDB();

    public static void main(String[] args) {
        while (true) {
            System.out.println("欢迎使用学籍管理系统！");
            System.out.println("1.查询学生名单");
            System.out.println("2.添加新学生信息");
            System.out.println("3.更新学生信息");
            System.out.println("4.删除学生信息");
            System.out.println("5.退出系统");
            System.out.println("请选择你的操作（1-5）");
            int choose = inInt.nextInt();
            switch (choose) {
                case 1:
                    selectUI();
                    break;
                case 2:
                    insertUI();
                    break;
                case 3:
                    updateUI();
                    break;
                case 4:
                    deleteUI();
                    break;
                case 5:
                    exitUI();
                    break;
            }
        }

    }

    private static void exitUI() {
        Sao.exit();
    }

    private static void deleteUI() {

    }

    private static void updateUI() {
        System.out.println("请输入要修改学生的学号！");
        String id = inString.nextLine();
        Student student = new Student();
        student=Sao.query(id);
        System.out.println("   学号  |" + "  姓名  |" + "   性别  |" + "   年龄  |" + "   班级  ");
        System.out.println(student.getId() + "   " + student.getName()
                + "       " + student.getSex() + "      " + student.getAge() + "        " + student.getClassName());
        System.out.println("请输入姓名");
        String name = inString.nextLine();
        System.out.println("请输入性别");
        String sex = inString.nextLine();
        System.out.println("请输入年龄");
        String age = inString.nextLine();
        System.out.println("请输入班级");
        String className = inString.nextLine();
        Student student1 = new Student(name,sex,age,className);
        Sao.update(student1);
    }

    private static void insertUI() {
        System.out.println("请输入学号");
        String id = inString.nextLine();
        System.out.println("请输入姓名");
        String name = inString.nextLine();
        System.out.println("请输入性别");
        String sex = inString.nextLine();
        System.out.println("请输入年龄");
        int age = inInt.nextInt();
        System.out.println("请输入班级");
        String className = inString.nextLine();
        System.out.println();
        System.out.println();
        Student student = new Student(id, name, age, sex, className);
        int c = Sao.insert(student);
        if (c > 0) {
            System.out.println("新学生信息添加成功");
        } else {
            System.out.println("添加失败");
        }
    }

    private static void selectUI() {
        System.out.println("学生名单：");
        System.out.println("   学号  |" + "  姓名  |" + "   性别  |" + "   年龄  |" + "   班级  ");
        ArrayList<Student> arrayList = Sao.selectAll();
        Iterator<Student> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Student student = iterator.next();
            System.out.println(student.getId() + "   " + student.getName()
                    + "       " + student.getSex() + "      " + student.getAge() + "        " + student.getClassName());
        }

    }
}
